package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.dto.BmiDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BmiController {
    @GetMapping("/bmi")
    @ResponseBody
    public String getResult(BmiDto bmiDto)
    {
        Double height = bmiDto.getHeight();
        Double weight = bmiDto.getWeight();
        Double bmi = weight/(height*height);
        if (bmi >= 27)
            return "too fat";
        else if (bmi >=24)
            return "little fat";
        else if (bmi >=18.5)
            return "standard";
        else
            return "too sick";
    }

    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height,@PathVariable Double weight)
    {
        double bmi = weight/(height*height);
        if (bmi >= 27)
            return "too fat";
        else if (bmi >=24)
            return "little fat";
        else if (bmi >=18.5)
            return "standard";
        else
            return "too sick";
    }

}
